﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PRO.Common;
using PRO.Entity;
using PRO.User;
using PRO.Product;
using PRO.Config;

namespace web.Member
{
    public partial class deliver_address : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            this.Title = "收货地址管理-" + BaseConfigs.Title;
            if (UserInfo.ID <= 0)
                Response.Redirect(string.Format("/login?url={0}", Request.RawUrl.UrlEncode()));
            else
            {
                if(!IsPostBack)
                    Bind();
            }
        }
        private void Bind()
        {
            this.Repeater1.DataSource = DeliverLib.GetMyDeliver_Address(UserInfo.ID);
            this.Repeater1.DataBind();
        }

        protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            int id = e.CommandArgument.ToInt(0);
            if (id != 0)
            {
                switch (e.CommandName.ToLower())
                {
                    case "default":
                        DeliverLib.SetDefault(id, UserInfo.ID);
                        Bind();
                        break;
                    case "del":
                        DeliverLib.DelDeliver_Address(id,UserInfo.ID);
                        Bind();
                        break;
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (CVGRequest.GetFormString("_a.d").IsNullOrWhiteSpace())
                Page.ClientScript.RegisterStartupScript(this.GetType(), "", "<script type='text/javascript'>alert('请选择送货地址！');</script>");
            else
                Response.Redirect("/deal/" + CVGRequest.GetFormString("_a.d"));
        }
    }
}